package com.food.service.impl;

import com.food.service.VerificationCodeService;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class VerificationCodeServiceImpl implements VerificationCodeService {
    
    private final Map<String, String> codeMap = new ConcurrentHashMap<>();
    private final Random random = new Random();

    @Override
    public String generateCode(String email) {
        String code = String.format("%06d", random.nextInt(1000000));
        codeMap.put(email, code);
        return code;
    }

    @Override
    public boolean verifyCode(String email, String code) {
        String savedCode = codeMap.get(email);
        if (savedCode != null && savedCode.equals(code)) {
            codeMap.remove(email);
            return true;
        }
        return false;
    }
} 